import 'package:flutter/material.dart';
import './tabs/catygory.dart';
import './tabs/home.dart';
import './tabs/setting.dart';
import './tabs/user.dart';
import './tabs/message.dart';

class MyTabs extends StatefulWidget {
  final int index;
  MyTabs({super.key, this.index = 4});

  @override
  State<MyTabs> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyTabs> {
  int _currentIndex =0;

  @override
  void initState() {
    super.initState();
    _currentIndex = widget.index;
  }
  final List<Widget> _pages = [
    HomePage(),
    CatygoryPage(),
    SettingPage(),
    UserPage(),
    MessagePage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Drawer侧边抽屉'),
        backgroundColor: const Color.fromARGB(255, 2, 209, 154),
      ),
      drawer: Drawer(
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  flex: 1,
                  child: UserAccountsDrawerHeader(
                    accountName: Text('牛哞哞'),
                    accountEmail: Text('123@qq.com'),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: NetworkImage(
                          'https://www.itying.com/images/flutter/1.png',
                        ),
                        fit: BoxFit.cover,
                      ),
                    ),
                    currentAccountPicture: ClipOval(
                      child: Image.network(
                        'https://www.itying.com/images/flutter/2.png',
                        fit: BoxFit.cover,
                        width: 40,
                        height: 40,
                      ),
                    ),
                    otherAccountsPictures: [
                      Image.network(
                        'https://www.itying.com/images/flutter/3.png',
                        fit: BoxFit.cover,
                      ),
                      Image.network(
                        'https://www.itying.com/images/flutter/4.png',
                        fit: BoxFit.cover,
                      ),
                      Image.network(
                        'https://www.itying.com/images/flutter/5.png',
                        fit: BoxFit.cover,
                      ),
                    ],
                  ),

                  // DrawerHeader(
                  //   decoration: BoxDecoration(
                  //     color: Colors.blue,
                  //     image: DecorationImage(
                  //       image: NetworkImage(
                  //         'https://www.itying.com/images/flutter/2.png',
                  //       ),
                  //       fit: BoxFit.cover,
                  //     ),
                  //   ),
                  //   child: Column(
                  //     children: [
                  //       // CircleAvatar(child: Icon(Icons.person)),
                  //       ListTile(
                  //         leading: ClipOval(
                  //           child: Image.network(
                  //             'https://www.itying.com/images/flutter/2.png',
                  //             fit: BoxFit.cover,
                  //             width: 40,
                  //             height: 40,
                  //           ),
                  //         ),
                  //         title: Text(
                  //           '个人中心',
                  //           style: TextStyle(color: Colors.yellow),
                  //         ),
                  //       ),
                  //       ListTile(
                  //         title:Text('邮箱：123@qq.com')
                  //       ),
                  //     ],
                  //   ),
                  // ),
                ),
              ],
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.person)),
              title: Text('个人中心'),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.settings)),
              title: Text('设置'),
            ),
            Divider(),
          ],
        ),
      ), //左边抽屉
      // endDrawer: Drawer(child: Text('右边抽屉')),//右边抽屉
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex, //默认选中第几个
        iconSize: 24, //底部菜单图标大小
        fixedColor: const Color.fromARGB(255, 20, 228, 200),
        type: BottomNavigationBarType.fixed, //4个（包含）以上菜单就要配置这个
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        }, //选中变化回调函数
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: '用户'),
          BottomNavigationBarItem(icon: Icon(Icons.message), label: '消息'),
        ],
      ),
      floatingActionButton: Container(
        width: 60,
        height: 60,
        padding: EdgeInsets.all(5),
        margin: EdgeInsets.only(top: 10),
        decoration: BoxDecoration(
          color: const Color.fromARGB(255, 245, 242, 242),
          borderRadius: BorderRadius.circular(30),
        ),
        child: ClipOval(
          //CircleAvatar
          child: FloatingActionButton(
            backgroundColor: _currentIndex == 2
                ? Colors.blue[50]
                : Colors.yellow[400],
            onPressed: () {
              // print('点击了FloatingActionButton');
              setState(() {
                _currentIndex = 2;
              });
            },
            child: Icon(Icons.add, size: 40),
          ),
        ),
      ),
      floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked, //配置FloatingActionButton的位置
    );
  }
}
